package com.bang.study.day06;

import java.util.Random;

/**
 * @Auther: Bang
 * @Date: 2019/9/17 0017 17:43
 * @Description:
 */
public class UFTest {

    public static double test(UF uf, int m) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < m; i++) {
            int a = random.nextInt(uf.getSize());
            int b = random.nextInt(uf.getSize());
            uf.unionElements(a, b);
        }
        for (int i = 0; i < m; i++) {
            int a = random.nextInt(uf.getSize());
            int b = random.nextInt(uf.getSize());
            uf.isConnected(a, b);
        }

        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

    public static void main(String[] args) {
        int size = 50000000;
        int m = 10000000;

//        UnionFind1 find1 = new UnionFind1(size);
//        double test1 = test(find1, m);
//        System.out.println("UnionFind1 time=" + test1);
//
//
//        UnionFind2 find2 = new UnionFind2(size);
//        double test2 = test(find2, m);
//        System.out.println("UnionFind2 time=" + test2);


//        UnionFind3 find3 = new UnionFind3(size);
//        print(test(find3, m), "UnionFind3 time=");
//
//
//        UnionFind4 find4 = new UnionFind4(size);
//        print(test(find4, m), "UnionFind4 time=");

        UnionFind5 find5 = new UnionFind5(size);
        print(test(find5, m), "UnionFind5 time=");


        UnionFind6 find6 = new UnionFind6(size);
        print(test(find6, m), "UnionFind6 time=");


    }

    private static void print(double test, String s) {
        double test4 = test;
        System.out.println(s + test4);
    }

}
